//
//  MainTabBarItem.swift
//  CZWeiBo06
//
//  Created by Mac on 15/8/10.
//  Copyright (c) 2015年 Mac. All rights reserved.
//

import UIKit

class MainTabBar: UITabBar {
    
    
    override func layoutSubviews() {
        
        let btnCount = 5
        
        let w = self.frame.size.width / 5
        let h = self.frame.size.height
        
        let frame = CGRectMake(0, 0, CGFloat(w), CGFloat(h))
        
        
        var index = 0
        
        for v in self.subviews as! [UIView] {
            
            if v is UIControl && !(v is UIButton){
                
                v.frame = CGRectOffset(frame, CGFloat(index) * w, 0)
                
                
                index++
                
                if index == 2  {
                    index++
                }


            }
            
      }
        
        
        self.addBtn.frame = CGRectOffset(frame, 2 * w, 0)
        
//        self.addBtn.center = CGPointMake(self.center.x, h * 0.5)
        
    }
    
    //懒加载
    lazy var addBtn : UIButton = {
        
        var btn = UIButton()
        
        btn.setImage(UIImage(named: "tabbar_compose_icon_add"), forState: UIControlState.Normal)
        btn.setImage(UIImage(named: "tabbar_compose_icon_add_highlighted"), forState: UIControlState.Highlighted)
        btn.setBackgroundImage(UIImage(named: "tabbar_compose_button"), forState: UIControlState.Normal)
        btn.setBackgroundImage(UIImage(named: "tabbar_compose_button_highlighted"), forState: UIControlState.Highlighted)
        
        self.addSubview(btn)
        
        return btn
    }()
}
